<template>
  <el-tabs v-model="activeName" @tab-click="handleClick">
    <el-tab-pane label="CFTC" name="first">
      <div class="role">
        <el-card shadow="never">
            <el-form :inline="true">
                <el-form-item label="时间:">
                  <el-date-picker size="medium"
                    v-model="CFTC.paramFrom.beginTime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                  </el-date-picker>&nbsp;-&nbsp;
                  <el-date-picker size="medium"
                    v-model="CFTC.paramFrom.endTime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                  </el-date-picker>

                </el-form-item>
                <br>
                <el-form-item label="持仓类型:">
                  <div>
                    <el-radio-group v-model="CFTC.paramFrom.positionType" size="medium">
                      <el-radio-button label="" >全部</el-radio-button>
                      <el-radio-button label="商业持仓" >商业持仓</el-radio-button>
                      <el-radio-button label="非商业持仓">非商业持仓</el-radio-button>
                    </el-radio-group>
                  </div>
                </el-form-item>
                <br>
                <el-form-item label="品种:">
                  <el-select v-model="CFTC.paramFrom.variety" placeholder="请选择" size="medium">
                    <el-option key="" label="全部" value=""></el-option>
                    <el-option
                      v-for="item in CFTC.options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                
            </el-form>
        </el-card>

        <el-card shadow="never" style="margin-top: 20px;">
          <el-row type="flex" justify="end" style="margin-bottom: 15px;">
            <el-button type="primary" size="mini" @click="CFTC.fn.add()">新增</el-button>
            <el-upload 
              :show-file-list="false" 
              :on-success="CFTC.fn.handleSuccess" 
              :on-error="CFTC.fn.handleError" 
              style="margin-left:20px"
              :headers="header" 
              :action="CFTC.action" 
              accept=".xlsx">
              <el-button size="mini" type="primary">批量导入</el-button>
            </el-upload>
          </el-row>
      <el-table border :data="CFTC.tableData" style="width: 100%">
        <el-table-column prop="holdingTime" align="center" label="时间" width="100px" />
        <el-table-column prop="positionType" align="center" label="持仓类型" width="100px" />
        <el-table-column prop="variety" align="center" label="品种" width="180px" />
        <el-table-column prop="positionValue" align="center" label="净仓位" width="100px" />
        <el-table-column prop="hb" align="center" label="净仓位环比" width="120px" />
        <el-table-column prop="nominalValue" align="center" label="空头" width="100px" />
        <el-table-column prop="hb" align="center" label="空头环比" width="100px" />
        <el-table-column prop="multipointValue" align="center" label="多头" width="100px"  />
        <el-table-column prop="hb" align="center" label="多头环比" width="100px" />
        <el-table-column prop="" align="center" label="操作" >
        <template v-slot="{ row }">
            <el-button type="warning" size="mini" @click="CFTC.fn.modify(row)">编辑</el-button>
            <el-button type="danger" size="mini" @click="CFTC.fn.del(row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <paging :page-size="CFTC.query.pageSize" 
        :total="CFTC.total" 
        :currentPage="CFTC.currentPage"
        @size-change="CFTC.fn.handleSizeChange"
        @current-change="CFTC.fn.handleCurrentChange" />
      <cftcAdd ref="cftcAdd" 
        :dialogTitle="CFTC.dialogTitle" 
        :dialog-visible.sync="CFTC.dialogVisible" 
        :form="CFTC.form" 
        :options="CFTC.options"
        :data="CFTC"
        @getStaffList="CFTC.fn.getInfo" />
    </el-card>



      </div>
      



    </el-tab-pane>
    <el-tab-pane label="ETFs" name="second">
      <div class="role">
        <el-card shadow="never">
            <el-form :inline="true">
                <el-form-item label="时间:">
                  <el-date-picker size="medium"
                    v-model="ETFS.paramFrom.beginTime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                  </el-date-picker>&nbsp;-&nbsp;
                  <el-date-picker size="medium"
                    v-model="ETFS.paramFrom.endTime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                  </el-date-picker>

                </el-form-item>
                <br>
                <el-form-item label="品种:">
                  <div>
                    <el-radio-group v-model="ETFS.paramFrom.gold" size="medium">
                      <el-radio-button label="" >全部</el-radio-button>
                      <el-radio-button label="黄金" >黄金</el-radio-button>
                      <el-radio-button label="白银">白银</el-radio-button>
                    </el-radio-group>
                  </div>
                </el-form-item>
                
                
            </el-form>
        </el-card>

        <el-card shadow="never" style="margin-top: 20px;">
          <el-row type="flex" justify="end" style="margin-bottom: 15px;">
            <el-button type="primary" size="mini" @click="ETFS.fn.add()">新增</el-button>
            <el-upload 
              :show-file-list="false" 
              :on-success="ETFS.fn.handleSuccess" 
              :on-error="ETFS.fn.handleError" 
              style="margin-left:20px"
              :headers="header" 
              :action="ETFS.action" 
              accept=".xlsx">
              <el-button size="mini" type="primary">批量导入</el-button>
            </el-upload>
          </el-row>
      <el-table border :data="ETFS.tableData" style="width: 100%">
        <el-table-column prop="holdingTime" align="center" label="时间" width="100px" />
        <el-table-column prop="gold" align="center" label="品种" width="180px" />
        <el-table-column prop="totalInventory" align="center" label="总库存(吨)" width="100px" />
        <el-table-column prop="decreaseHoldings" align="center" label="增持/减持(吨)" width="100px" />
        <el-table-column prop="assetValue" align="center" label="资产净值(美元)" width="100px" />
        <el-table-column prop="" align="center" label="操作" >
        <template v-slot="{ row }">
            <el-button type="warning" size="mini" @click="ETFS.fn.modify(row)">编辑</el-button>
            <el-button type="danger" size="mini" @click="ETFS.fn.del(row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <paging :page-size="ETFS.query.pageSize" 
        :total="ETFS.total" 
        :currentPage="ETFS.currentPage"
        @size-change="ETFS.fn.handleSizeChange"
        @current-change="ETFS.fn.handleCurrentChange" />
      <etfsAdd ref="etfsAdd" 
        :dialogTitle="ETFS.dialogTitle" 
        :dialog-visible.sync="ETFS.dialogVisible" 
        :form="ETFS.form" 
        :options="ETFS.options"
        :data="ETFS"
        @getStaffList="ETFS.fn.getInfo" />
    </el-card>



      </div>
      
    </el-tab-pane>
    <el-tab-pane label="LME" name="third">
      <el-tabs v-model="thirdActiveName" type="card" @tab-click="handleClick">
        <el-tab-pane label="库存" name="first">
          <div class="role">
        <el-card shadow="never">
            <el-form :inline="true">
                <el-form-item label="时间:">
                  <el-date-picker size="medium"
                    v-model="LME_INVENTORY.paramFrom.beginTime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                  </el-date-picker>&nbsp;-&nbsp;
                  <el-date-picker size="medium"
                    v-model="LME_INVENTORY.paramFrom.endTime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                  </el-date-picker>

                </el-form-item>
                <br>
                <el-form-item label="品种:">
                  <el-select v-model="LME_INVENTORY.paramFrom.variety" placeholder="请选择" size="medium">
                    <el-option key="" label="全部" value=""></el-option>
                    <el-option
                      v-for="item in LME_INVENTORY.options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                
                
                
            </el-form>
        </el-card>

        <el-card shadow="never" style="margin-top: 20px;">
          <el-row type="flex" justify="end" style="margin-bottom: 15px;">
            <el-button type="primary" size="mini" @click="LME_INVENTORY.fn.add()">新增</el-button>
            <el-upload 
              :show-file-list="false" 
              :on-success="LME_INVENTORY.fn.handleSuccess" 
              :on-error="LME_INVENTORY.fn.handleError" 
              style="margin-left:20px"
              :headers="header" 
              :action="LME_INVENTORY.action" 
              accept=".xlsx">
              <el-button size="mini" type="primary">批量导入</el-button>
            </el-upload>
          </el-row>
      <el-table border :data="LME_INVENTORY.tableData" style="width: 100%">
        <el-table-column prop="lmeTime" align="center" label="时间" width="100px" />
        <el-table-column prop="variety" align="center" label="品种" width="100px" />
        <el-table-column prop="initialStock" align="center" label="初期库存" width="100px" />
        <el-table-column prop="deliveryValue" align="center" label="出库" width="100px" />
        <el-table-column prop="inputValue" align="center" label="入库" width="100px" />
        <el-table-column prop="stockChange" align="center" label="库存变化" width="100px" />
        <el-table-column prop="endStock" align="center" label="末期库存" width="100px" />
        <el-table-column prop="warehouseReceipt" align="center" label="注册仓单" width="100px" />
        <el-table-column prop="cancellationReceipt" align="center" label="注销仓单" width="100px" />
        <el-table-column prop="receiptProportion" align="center" label="注销仓单比例" width="150px" />
        <el-table-column prop="" align="center" label="操作" >
        <template v-slot="{ row }">
            <el-button type="warning" size="mini" @click="LME_INVENTORY.fn.modify(row)">编辑</el-button>
            <el-button type="danger" size="mini" @click="LME_INVENTORY.fn.del(row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <paging :page-size="LME_INVENTORY.query.pageSize" 
        :total="LME_INVENTORY.total" 
        :currentPage="LME_INVENTORY.currentPage"
        @size-change="LME_INVENTORY.fn.handleSizeChange"
        @current-change="LME_INVENTORY.fn.handleCurrentChange" />
      <lmeInventoryAdd ref="lmeInventoryAdd" 
        :dialogTitle="LME_INVENTORY.dialogTitle" 
        :dialog-visible.sync="LME_INVENTORY.dialogVisible" 
        :form="LME_INVENTORY.form" 
        :options="LME_INVENTORY.options"
        :data="LME_INVENTORY"
        @getStaffList="LME_INVENTORY.fn.getInfo" />
    </el-card>



      </div>
        </el-tab-pane>
        <el-tab-pane label="持仓" name="second">
          <div class="role">
        <el-card shadow="never">
            <el-form :inline="true">
                <el-form-item label="时间:">
                  <el-date-picker size="medium"
                    v-model="LME_POSITION.paramFrom.beginTime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                  </el-date-picker>&nbsp;-&nbsp;
                  <el-date-picker size="medium"
                    v-model="LME_POSITION.paramFrom.endTime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                  </el-date-picker>

                </el-form-item>
                <br>
                <el-form-item label="品种:">
                  <el-select v-model="LME_POSITION.paramFrom.variety" placeholder="请选择" size="medium">
                    <el-option key="" label="全部" value=""></el-option>
                    <el-option
                      v-for="item in LME_POSITION.options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                
                
                
            </el-form>
        </el-card>

        <el-card shadow="never" style="margin-top: 20px;">
          <el-row type="flex" justify="end" style="margin-bottom: 15px;">
            <el-button type="primary" size="mini" @click="LME_POSITION.fn.add()">新增</el-button>
            <el-upload 
              :show-file-list="false" 
              :on-success="LME_POSITION.fn.handleSuccess" 
              :on-error="LME_POSITION.fn.handleError" 
              style="margin-left:20px"
              :headers="header" 
              :action="LME_POSITION.action" 
              accept=".xlsx">
              <el-button size="mini" type="primary">批量导入</el-button>
            </el-upload>
          </el-row>
      <el-table border :data="LME_POSITION.tableData" style="width: 100%">
        <el-table-column prop="positionTime" align="center" label="时间" width="100px" />
        <el-table-column prop="variety" align="center" label="品种" width="100px" />
        <el-table-column prop="positionValue" align="center" label="净仓位" width="100px" />
        <el-table-column prop="hb" align="center" label="净仓位环比" width="100px" />
        <el-table-column prop="multipointValue" align="center" label="多头" width="100px" />
        <el-table-column prop="hb" align="center" label="多头环比" width="100px" />
        <el-table-column prop="nominalValue" align="center" label="空头" width="100px" />
        <el-table-column prop="hb" align="center" label="空头环比" width="100px" />
        <el-table-column prop="" align="center" label="操作" >
        <template v-slot="{ row }">
            <el-button type="warning" size="mini" @click="LME_POSITION.fn.modify(row)">编辑</el-button>
            <el-button type="danger" size="mini" @click="LME_POSITION.fn.del(row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <paging :page-size="LME_POSITION.query.pageSize" 
        :total="LME_POSITION.total"
        :currentPage="LME_POSITION.currentPage" 
        @size-change="LME_POSITION.fn.handleSizeChange"
        @current-change="LME_POSITION.fn.handleCurrentChange" />
      <lmePositionAdd ref="lmePositionAdd" 
        :dialogTitle="LME_POSITION.dialogTitle" 
        :dialog-visible.sync="LME_POSITION.dialogVisible" 
        :form="LME_POSITION.form" 
        :options="LME_POSITION.options"
        :data="LME_POSITION"
        @getStaffList="LME_POSITION.fn.getInfo" />
    </el-card>



      </div>
        </el-tab-pane>
        
      </el-tabs>

    </el-tab-pane>
  </el-tabs>



 
</template>
<script>
import cftcAdd from './cftc/cftcAdd.vue'
import etfsAdd from './etfs/etfsAdd.vue'
import lmeInventoryAdd from './lme/lmeInventoryAdd.vue'
import lmePositionAdd from './lme/lmePositionAdd.vue'
import paging from '@/components/paging.vue'
import {  
  CFTCApi,
  ETFSApi,
  LME_INVENTORYApi,
  LME_POSITIONApi} from "./commodityExchangeIndex.js";
import baseData from '@/baseData'
import Cookies from 'js-cookie'
import { TOKEN_KEY } from "@/constants/KEY";
export default {
    name: 'CommodityExchange',
    components: {
      paging,
      cftcAdd,
      etfsAdd,
      lmeInventoryAdd,
      lmePositionAdd,
    },
    data() {
      return {
       activeName: 'first',
       thirdActiveName: 'first',
       CFTC:{
        dialogTitle:'新增1',
        dialogVisible: false,
        form:{},
        action:baseData.basePathAdmin+"/CriteriaAPIStructure/uploadPatternsCFTCExcel",
        paramFrom:{
          beginTime:'',
          endTime:'',
          positionType:'',
          variety:'',
        },
        tableData:[],
        options: [],
        query:{
          pageSize:10,
          page:1
        },
        currentPage:1,
        total:0,
        fn:{submit:{}},
      },
       ETFS:{
        dialogTitle:'新增1',
        dialogVisible: false,
        form:{},
        action:baseData.basePathAdmin+"/CriteriaAPIStructure/uploadPatternsETFsExcel",
        paramFrom:{
          beginTime:'',
          endTime:'',
          positionType:'',
          gold:'',
        },
        tableData:[],
        options: [],
        query:{
          pageSize:10,
          page:1
        },
        currentPage:1,
        total:0,
        fn:{}, 
       },
       LME_INVENTORY:{
        dialogTitle:'新增1',
        dialogVisible: false,
        form:{},
        action:baseData.basePathAdmin+"/CriteriaAPIStructure/uploadLmeInventoryExcel",
        paramFrom:{
          beginTime:'',
          endTime:'',
          positionType:'',
          variety:'',
        },
        tableData:[],
        options: [],
        query:{
          pageSize:10,
          page:1
        },
        currentPage:1,
        total:0,
        fn:{submit:{}},
       },
       LME_POSITION:{
        dialogTitle:'新增1',
        dialogVisible: false,
        form:{},
        action:baseData.basePathAdmin+"/CriteriaAPIStructure/uploadLmePositionExcel",
        paramFrom:{
          beginTime:'',
          endTime:'',
          positionType:'',
          variety:'',
        },
        tableData:[],
        options: [],
        query:{
          pageSize:10,
          page:1
        },
        currentPage:1,
        total:0,
        fn:{}, 
       },
       header: {
        Authentication: Cookies.get(TOKEN_KEY)
      },
      }
    },
  
    mounted() {
      window.common = this
      this.CFTC.fn = this.CFTCfn()
      this.ETFS.fn =this.ETFSfn()
      this.LME_INVENTORY.fn = this.LME_INVENTORYfn()
      this.LME_POSITION.fn=this.LME_POSITIONfn()
      this.CFTC.fn.init()
      this.ETFS.fn.init()
      this.LME_INVENTORY.fn.init()
      this.LME_POSITION.fn.init()

      this.CFTC.fn.selectAllVariety()
      this.LME_INVENTORY.fn.selectAllVariety()
    },
    watch:{

      'CFTC.paramFrom': {
        handler(newValue, oldValue) {
          this.CFTC.fn.query()
          //console.log('User changed:', newValue);
        },
        // 是否在选项声明时立即触发
        immediate: false,
        // 是否深度监听
        deep: true
      },
      'ETFS.paramFrom': {
        handler(newValue, oldValue) {
          this.ETFS.fn.query()
          //console.log('User changed:', newValue);
        },
        // 是否在选项声明时立即触发
        immediate: false,
        // 是否深度监听
        deep: true
      },
      'LME_INVENTORY.paramFrom': {
        handler(newValue, oldValue) {
          this.LME_INVENTORY.fn.query()
          //console.log('User changed:', newValue);
        },
        // 是否在选项声明时立即触发
        immediate: false,
        // 是否深度监听
        deep: true
      },
      'LME_POSITION.paramFrom': {
        handler(newValue, oldValue) {
          this.LME_POSITION.fn.query()
          //console.log('User changed:', newValue);
        },
        // 是否在选项声明时立即触发
        immediate: false,
        // 是否深度监听
        deep: true
      }
    },
    methods: {
      handleClick(tab, event) {
        //console.log(tab, event);
      },
      CFTCfn(){
        const that = this;
        let that_data = that.CFTC
        const that_api = CFTCApi()
        
        const fn = {
          init(){
            that_data = that.CFTC
          },
          handleSuccess(res){
            that.$message({
                type: 'success',
                message: res.msg
              })
            that_data.fn.query()
          },
          add(){
            that_data.dialogTitle = '新增'
            that_data.form = {
              positionType:'商业持仓',
              variety:'黄金',
            }
            that_data.dialogVisible = true
          },
          modify(row){
            that_data.dialogTitle = '编辑'
            that_data.form = row
            that_data.dialogVisible = true
          },
          async submit(){

            if(that_data.form.id){
              const res = await that_api.edit(that_data.form);
              that_data.dialogVisible = false
              that_data.fn.getInfo();
            }else{
              const res = await that_api.add(that_data.form);
              that_data.dialogVisible = false
              that_data.fn.getInfo();
            }
            
          },
          async selectAllVariety(){
            const data = await that_api.selectAllVariety()
            const options = []
            data.forEach(element => {
              options.push({
                value: element,
                label: element
              })
            });
            that_data.options = options
          },
          query(){
            that_data.query.page = 1
            that_data.currentPage = 1
            that_data.fn.getInfo();
          },
          async getInfo(){
            const data = await that_api.getPage({
              ...that_data.query,
              ...that_data.paramFrom})
            that_data.tableData = data.records
            that_data.total = data.total
            that_data.currentPage = that_data.query.page
          },
          handleSizeChange(){
            
          },
          handleCurrentChange(val){
            that_data.currentPage = val
            that_data.query.page = val
            that_data.fn.getInfo()
          },
          del(id){
            that.$confirm('你确定要删除吗?', '删除', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(async () => {
              const res = await that_api.del(id)
              that_data.fn.getInfo()
              
            }).catch(() => {
              that.$message({
                type: 'success',
                message: '已取消删除'
              })
            })
          }
        }
        return fn
      },
      ETFSfn(){
        const that = this;
        let that_data = that.ETFS
        const that_api = ETFSApi()
        const fn = {
          init(){
            that_data = that.ETFS
          },
          handleSuccess(res){
            that.$message({
                type: 'success',
                message: res.msg
              })
            that_data.fn.query()
          },
          add(){
            that_data.dialogTitle = '新增'
            that_data.form = {
              
              gold:'黄金',
            }
            that_data.dialogVisible = true
          },
          modify(row){
            that_data.dialogTitle = '编辑'
            that_data.form = row
            that_data.dialogVisible = true
          },
          async submit(){

            if(that_data.form.id){
              const res = await that_api.edit(that_data.form);
              that_data.dialogVisible = false
              that_data.fn.getInfo();
            }else{
              const res = await that_api.add(that_data.form);
              that_data.dialogVisible = false
              that_data.fn.getInfo();
            }
            
          },
          async selectAllVariety(){
            const data = await that_api.selectAllVariety()
            const options = []
            data.forEach(element => {
              options.push({
                value: element,
                label: element
              })
            });
            that_data.options = options
          },
          query(){
            that_data.query.page = 1
            that_data.currentPage = 1
            that_data.fn.getInfo();
          },
          async getInfo(){
            const data = await that_api.getPage({
              ...that_data.query,
              ...that_data.paramFrom})
            that_data.tableData = data.records
            that_data.total = data.total
          },
          handleSizeChange(){
            
          },
          handleCurrentChange(val){
            that_data.currentPage = val
            that_data.query.page = val
            that_data.fn.getInfo()
          },
          del(id){
            that.$confirm('你确定要删除吗?', '删除', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(async () => {
              const res = await that_api.del(id)
              that_data.fn.getInfo()
              
            }).catch(() => {
              that.$message({
                type: 'success',
                message: '已取消删除'
              })
            })
          }
        }
        return fn
      },
      LME_INVENTORYfn(){
        const that = this;
        let that_data = that.LME_INVENTORY
        const that_api = LME_INVENTORYApi()
        const fn = {
          init(){
            that_data = that.LME_INVENTORY
          },
          handleSuccess(res){
            that.$message({
                type: 'success',
                message: res.msg
              })
              that_data.fn.query()
          },
          add(){
            that_data.dialogTitle = '新增'
            that_data.form = {
              
              gold:'黄金',
            }
            that_data.dialogVisible = true
          },
          modify(row){
            that_data.dialogTitle = '编辑'
            that_data.form = row
            that_data.dialogVisible = true
          },
          async submit(){

            if(that_data.form.id){
              const res = await that_api.edit(that_data.form);
              that_data.dialogVisible = false
              that_data.fn.getInfo();
            }else{
              const res = await that_api.add(that_data.form);
              that_data.dialogVisible = false
              that_data.fn.getInfo();
            }
            
          },
          async selectAllVariety(){
            const data = await that_api.selectAllVariety()
            const options = []
            data.forEach(element => {
              options.push({
                value: element,
                label: element
              })
            });
            that_data.options = options
            that.LME_POSITION.options = options
          },
          query(){
            that_data.query.page = 1
            that_data.currentPage = 1
            that_data.fn.getInfo();
          },
          async getInfo(){
            const data = await that_api.getPage({
              ...that_data.query,
              ...that_data.paramFrom})
            that_data.tableData = data.records
            that_data.total = data.total
          },
          handleSizeChange(){
            
          },
          handleCurrentChange(val){
            that_data.currentPage = val
            that_data.query.page = val
            that_data.fn.getInfo()
          },
          del(id){
            that.$confirm('你确定要删除吗?', '删除', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(async () => {
              const res = await that_api.del(id)
              that_data.fn.getInfo()
              
            }).catch(() => {
              that.$message({
                type: 'success',
                message: '已取消删除'
              })
            })
          }
        }
        return fn
      },
      LME_POSITIONfn(){
        const that = this;
        let that_data = that.LME_POSITION
        const that_api = LME_POSITIONApi()
        const fn = {
          init(){
            that_data = that.LME_POSITION
          },
          handleSuccess(res){
            that.$message({
                type: 'success',
                message: res.msg
              })
            that_data.fn.query()
          },
          add(){
            that_data.dialogTitle = '新增'
            that_data.form = {
              
              gold:'黄金',
            }
            that_data.dialogVisible = true
          },
          modify(row){
            that_data.dialogTitle = '编辑'
            that_data.form = row
            that_data.dialogVisible = true
          },
          async submit(){

            if(that_data.form.id){
              const res = await that_api.edit(that_data.form);
              that_data.dialogVisible = false
              that_data.fn.getInfo();
            }else{
              const res = await that_api.add(that_data.form);
              that_data.dialogVisible = false
              that_data.fn.getInfo();
            }
            
          },
          async selectAllVariety(){
            const data = awaitthat_api.selectAllVariety()
            const options = []
            data.forEach(element => {
              options.push({
                value: element,
                label: element
              })
            });
            that_data.options = options
          },
          query(){
            that_data.query.page = 1
            that_data.currentPage = 1
            that_data.fn.getInfo();
          },
          async getInfo(){
            const data = await that_api.getPage({
              ...that_data.query,
              ...that_data.paramFrom})
            that_data.tableData = data.records
            that_data.total = data.total
          },
          handleSizeChange(){
            
          },
          handleCurrentChange(val){
            that_data.currentPage = val
            that_data.query.page = val
            that_data.fn.getInfo()
          },
          del(id){
            that.$confirm('你确定要删除吗?', '删除', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(async () => {
              const res = await that_api.del(id)
              that_data.fn.getInfo()
              
            }).catch(() => {
              that.$message({
                type: 'success',
                message: '已取消删除'
              })
            })
          }
        }
        return fn
      },
    }
    
  }
  </script>